//
//  HSScoreTableViewCell.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/10/10.
//  Copyright © 2016年 黄华强. All rights reserved.
//

import UIKit

class HSScoreTableViewCell: UITableViewCell {

    var esTitle:UILabel!
    var teachNameLabel:UILabel!
    var subjectsButton:UIButton!
    var timeLabel:UILabel!
    var stateImageView:UIImageView!
    var scoreLabel:UILabel!
    var isPassLabel:UILabel!
    var a:UILabel = UILabel()
    
    var model:HSScoreModel? {
        didSet {
            esTitle.text = model?.es_title
            teachNameLabel.text = model?.es_teacherName
            subjectsButton.setTitle(model?.es_course, for: .normal)
            timeLabel.text = model?.es_createDate
            let score = model?.es_score ?? 0
            
            scoreLabel.text = "\(score)"
            if score < 60 {
                stateImageView.image = UIImage(named: "scores_ng")
                isPassLabel.text = "不合格"
            } else {
                stateImageView.image = UIImage(named: "scores_ok")
                isPassLabel.text = "合格"
            }
            
            let teachComment = model?.es_comment ?? ""
            a.text = "老师评语：\(teachComment)"
            
            if (model?.isShowComment)! {
                a.isHidden = false
            } else {
                
                a.isHidden = true
                
            }
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        esTitle = UILabel(frame: CGRect(x: 12, y: 8, width: 200, height: 20))
        esTitle.text = "作业标题"
        esTitle.font = UIFont.systemFont(ofSize: UIScreen.main.bounds.width * 0.04)
        contentView.addSubview(esTitle)
        
        teachNameLabel = UILabel(frame: CGRect(x: UIScreen.main.bounds.width * 0.5, y: 8, width: UIScreen.main.bounds.width * 0.25, height: 20))
        teachNameLabel.text = "王老师"
        teachNameLabel.textAlignment = NSTextAlignment.right
        teachNameLabel.font = UIFont.systemFont(ofSize: UIScreen.main.bounds.width * 0.035)
        contentView.addSubview(teachNameLabel)
        
        subjectsButton = UIButton(frame: CGRect(x: 12, y: 36, width: 36, height: 16))
        subjectsButton.layer.cornerRadius = 8
        subjectsButton.setTitle("数学", for: .normal)
        subjectsButton.setTitleColor(#colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1), for: .normal)
        subjectsButton.titleLabel?.font = UIFont.systemFont(ofSize: UIScreen.main.bounds.width * 0.03)
        subjectsButton.isUserInteractionEnabled = false
        subjectsButton.layer.borderColor = #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1).cgColor
        subjectsButton.layer.borderWidth = 1
        contentView.addSubview(subjectsButton)
        
        timeLabel = UILabel(frame: CGRect(x: UIScreen.main.bounds.width * 0.4, y: 40, width: UIScreen.main.bounds.width * 0.35, height: 20))
        timeLabel.textAlignment = NSTextAlignment.right
        timeLabel.textColor = #colorLiteral(red: 0.6980392157, green: 0.6980392157, blue: 0.6980392157, alpha: 1)
        timeLabel.text = "2016-10-10 08:08"
        timeLabel.font = UIFont.systemFont(ofSize: UIScreen.main.bounds.width * 0.035)
        contentView.addSubview(timeLabel)
        
        stateImageView = UIImageView(frame: CGRect(origin: CGPoint(x: UIScreen.main.bounds.width * 0.8, y: 6), size: CGSize(width: 56, height: 56)))
        stateImageView.image = UIImage(named: "scores_ok")
        contentView.addSubview(stateImageView)
        
        scoreLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 56, height: 28))
        scoreLabel.font = UIFont.systemFont(ofSize: UIScreen.main.bounds.width * 0.05)
        scoreLabel.text = "98"
        scoreLabel.textColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        scoreLabel.textAlignment = NSTextAlignment.center
        stateImageView.addSubview(scoreLabel)
        
        isPassLabel = UILabel(frame: CGRect(x: 0, y: 28, width: 56, height: 20))
        isPassLabel.font = UIFont.systemFont(ofSize: UIScreen.main.bounds.width * 0.035)
        isPassLabel.text = "合格"
        isPassLabel.textColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        isPassLabel.textAlignment = NSTextAlignment.center
        stateImageView.addSubview(isPassLabel)
        
        a = UILabel(title: "", color: #colorLiteral(red: 0.2980392157, green: 0.2980392157, blue: 0.2980392157, alpha: 1), fontSize: 13)
        a.numberOfLines = 0
        a.backgroundColor = #colorLiteral(red: 0.9411764706, green: 0.9411764706, blue: 0.9411764706, alpha: 1)
        contentView.addSubview(a)
        a.snp.makeConstraints { (make) in
            make.left.equalTo(8)
            make.right.equalTo(-8)
            make.top.equalTo(68)
            make.bottom.equalTo(-8)
        }

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
